package vn.aptech.scrumgroup.model;

import vn.aptech.scrumgroup.util.DrawUtil;
import android.graphics.Canvas;
import android.graphics.Paint;
import android.graphics.Paint.Style;
import android.graphics.Path;
import android.graphics.Rect;
import demo.axitdn.physic.Unit;

public class PlanningObjectModel extends AbstractBaseModel{
	private float Ox;
	private float Oy;
	private float width;
	private float height;
	private float radius;
	private float textHeight;
	private Path shapePath;
	private String[] lines = new String[]{"Team Selects", "How Much To", "Commit To Do", "By Sprint's End"};
//	private String line1="Team Selects";
//	private String line2="How Much To";
//	private String line3="Commit To Do";
//	private String line4="By Sprint's End";
//	private String[] footer = new String[]{"Sprint Planning", "Meeting"};
	private String line5="Sprint Planning";
	private String line6="Meeting";
	public PlanningObjectModel(float Ox,float Oy,float width,float height, int backColor, int foreColor)
	{
		super(backColor, foreColor);
		this.Ox=Ox;
		this.Oy=Oy;
		this.width=width;
		this.height=height;
		this.radius=width/2;
		this.shapePath=new Path();
		setPath();
	}
	public PlanningObjectModel(float Ox,float Oy,float radius, int backColor, int foreColor)
	{
		super(backColor, foreColor);
		this.Ox=Ox;
		this.Oy=Oy;
		this.radius=radius;
		this.width=2*radius;
		this.height=radius*4/3;
		this.shapePath=new Path();
		setPath();
	}
	public void setPath()
	{
		this.shapePath.moveTo(Ox-width/2, Oy);
		shapePath.lineTo(Ox-width/2-width/7, Oy-height/2);
		shapePath.lineTo(Ox+width/2-width/7, Oy-height/2);
		shapePath.lineTo(Ox+width/2,Oy);
		shapePath.lineTo(Ox+width/2-width/7,Oy+height/2);
		shapePath.lineTo(Ox-width/2-width/7, Oy+height/2);
		shapePath.lineTo(Ox-width/2, Oy);
		shapePath.close();
	}
	public void drawText(Canvas canvas)
	{
		Paint p=new Paint(Paint.ANTI_ALIAS_FLAG);
		//p.setARGB(255, 51, 122, 162);
		p.setTextSize(DrawUtil.calculateTextSize(lines, this.width, p, 3));
		p.setColor(foreColor);
		float textSize=radius/4;
		float align=radius/10;
		p.setTextSize(textSize);
		
		Rect bounds=new Rect();
		float textHeight = 0;
		for(int i = 0; i< this.lines.length; i++){
			p.getTextBounds(this.lines[i], 0, this.lines[i].length(), bounds);
			textHeight += bounds.height();
		}
//		p.getTextBounds(this.line1, 0, this.line1.length(), bounds);
//		canvas.drawText(line1, Ox-radius+align, Oy-textSize, p);
//		p.getTextBounds(this.line2, 0, this.line2.length(), bounds);
//		canvas.drawText(line2, Ox-radius+align, Oy, p);
//		p.getTextBounds(this.line3, 0, this.line3.length(), bounds);
//		canvas.drawText(line3, Ox-radius+align, Oy+textSize, p);
//		p.getTextBounds(this.line4, 0, this.line4.length(), bounds);
//		canvas.drawText(line4, Ox-radius+align, Oy+2*textSize, p);
		p.getTextBounds(this.lines[0], 0, this.lines[0].length(), bounds);
		float currentY = Oy - height/2 + (height - textHeight)/2 + 3;	//Oy - height/2 + 3 + (height - textHeight - 3 + 3)/2
		canvas.drawText(lines[0], Ox-radius+align, currentY, p);
		
		for(int i = 1; i < lines.length; i++){
			p.getTextBounds(this.lines[i-1], 0, this.lines[i-1].length(), bounds);
			currentY = currentY + bounds.height();
			canvas.drawText(lines[i], Ox-radius+align, currentY, p);
		}
		
		p.setTextSize(3*textSize/2);
		p.setStyle(Style.FILL_AND_STROKE);
		p.setStrokeWidth(1);
		p.getTextBounds(this.line5, 0, this.line5.length(), bounds);
		canvas.drawText(line5, Ox-bounds.width()/2, Oy+height/2+bounds.height(), p);
		p.getTextBounds(this.line6, 0, this.line6.length(), bounds);
		canvas.drawText(line6, Ox-bounds.width()/2, Oy+height/2+2*bounds.height(), p);
		this.textHeight=bounds.height();
	}

	@Override
	public boolean isPointOf(float x, float y) {
		if(x>=(Ox-width/2-width/7)&&x<=(Ox+width/2)&&y>=(Oy-height/2)&&y<=(Oy+height/2+2*textHeight)) return true;
		return false;
	}
	@Override
	public void changeColor(int color) {
		// TODO Auto-generated method stub
		
	}
	@Override
	public void onDraw(Canvas c) {
		// TODO Auto-generated method stub
		Paint p =new Paint();
		p.setColor(backColor);
		p.setStyle(Style.STROKE);
		p.setStrokeWidth(3);
		c.drawPath(shapePath, p);
		drawText(c);
	}
	@Override
	public void onUpdate(double t) {
		// TODO Auto-generated method stub
		
	}

}
